package org.elsfs.cloud.common.mybatis.ext.sql.support.union;


import org.elsfs.cloud.common.mybatis.ext.sql.SqlFragment;
import org.elsfs.cloud.common.util.lang.StringUtils;

/**
 * 联合项
 *

 */
public interface UnionItem extends SqlFragment {

    /**
     * 剔除条件SQL头部多余的关键词
     *
     * @param unionSql 联合SQL
     * @return 合理的联合SQL
     */
    static String stripHeaderKeyword(String unionSql) {
        if (unionSql.startsWith("UNION ")) {
            return StringUtils.strip(unionSql, "UNION ");
        }

        if (unionSql.startsWith("UNION ALL ")) {
            return StringUtils.strip(unionSql, "UNION ALL ");
        }

        return unionSql;
    }
}
